package com.muslimedia.reloadmanager.adapter;

import java.util.List;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.muslimedia.reloadmanager.R;
import com.muslimedia.reloadmanager.model.Menu;

public class MenuAdapter extends BaseAdapter {
	private Activity mActivity;
	private List<Menu> menus;

    
    public MenuAdapter(Activity activity, List<Menu> menus){
    	super();
    	mActivity = activity;
    	this.menus = menus;
    }

    public int getCount() {
        return menus.size();
    }

    public Object getItem(int position) {
        return null;
    }

    public long getItemId(int position) {
        return 0;
    }

    // create a new ImageView for each item referenced by the Adapter
    public View getView(int position, View convertView, ViewGroup parent) {
    	ViewHolder view = null;
        LayoutInflater inflator = mActivity.getLayoutInflater();
        
    	ImageView imageView = null;
        if (convertView == null) {  // if it's not recycled, initialize some attributes
        	view = new ViewHolder();
            convertView = inflator.inflate(R.layout.gridview_row, null);
            view.txtViewTitle = (TextView) convertView.findViewById(R.id.textView1);
            view.imgViewFlag = (ImageView) convertView.findViewById(R.id.imageView1);
            convertView.setTag(view);            
            
            /*imageView = new ImageView(mActivity);
            imageView.setLayoutParams(new GridView.LayoutParams(85, 85));
            imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
            imageView.setPadding(8, 8, 8, 8);*/
        } else {
        	view = (ViewHolder) convertView.getTag();
        }

        view.imgViewFlag.setImageResource(menus.get(position).getThumb());
        view.txtViewTitle.setText(menus.get(position).getTitle());
        return convertView;
    }
    
    public static class ViewHolder
    {
        public ImageView imgViewFlag;
        public TextView txtViewTitle;
    }
}
